import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yuan_hang_app/utils/common_req_utils.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/widget/common_attachment.dart';
import 'package:yuan_hang_app/widget/label_item.dart';
import '../../../../../res/w_colors.dart';
import '../../../../../res/w_dimens.dart';
import '../../../../../widget/w_text.dart';
import '../../../model/leads.dart';

class LeadsInfoList extends StatelessWidget {
  final Leads leads;
  final GlobalKey picKey;

  const LeadsInfoList({super.key, required this.leads, required this.picKey});

  @override
  Widget build(BuildContext context) {
    List picList = (leads.filesList ?? [])
        .map((item) => item["fileUploadInfoId"])
        .toList();
    List picUrlList =
        (leads.filesList ?? []).map((item) => item["url"]).toList();

    return ListView(
      padding: EdgeInsets.zero,
      children: [
        LabelItem(label: "客户名称", value: leads.customerName ?? ""),
        LabelItem(
            label: "性别",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.sex, leads.sex)),
        LabelItem(label: "手机号码", value: leads.phone),
        LabelItem(label: "微信号", value: leads.wechat),
        LabelItem(
            label: "客户类型",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.customerType, leads.customerType)),
        LabelItem(label: "公司名称", value: leads.companyName),
        LabelItem(
            label: "意向级别",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.intentRange, leads.level)),
        LabelItem(label: "意向车型", value: leads.modelName),
        LabelItem(
            label: "线索来源",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.leaderSource, leads.clueSource)),
        LabelItem(label: "市场活动", value: leads.activityName),
        LabelItem(
            label: "证件类型",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.cardType, leads.idType)),
        LabelItem(label: "证件号码", value: leads.idNo),
        LabelItem(
          label: "省市区",
          value: "${leads.provinceName}${leads.cityName}${leads.countyName}",
        ),
        LabelItem(label: "详细地址", value: leads.address),
        LabelItem(
            label: "线索状态",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.leadsStatus, leads.status)),
        LabelItem(label: "直营店", value: leads.shopName.toString()),
        LabelItem(label: "销售顾问", value: leads.salemanName.toString()),
        LabelItem(label: "线索创建时间", value: leads.createdAt),
        LabelItem(label: "线索下发时间", value: leads.distributeDate),
        LabelItem(label: "意向购车日期", value: leads.purchaseDate),
        LabelItem(
            label: "是否置换",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.yesOrNo, leads.isSubstitution)),
        LabelItem(
            label: "是否需要贷款",
            value: CommonReqUtils.exchangeCodeToName(
                CommonReqUtils.yesOrNo, leads.isLoan)),
        LabelItem(label: "购车预算", value: leads.budgetAmount),
        LabelItem(label: "客户生日", value: leads.birthday),
        LabelItem(label: "年龄", value: leads.age == null ? "" : leads.age.toString()),
        LabelItem(label: "电子邮箱", value: leads.eMail),
        const LabelItem(
          label: "客户标签",
          value: "",
          isLast: true,
        ),
        if (leads.appCustomerTagList != null &&
            leads.appCustomerTagList!.isNotEmpty)
          Container(
            decoration: BoxDecoration(
                color: Colors.white,
                border: Border(
                  bottom: BorderSide(
                    color: WColors.border, // 边框颜色
                    width: 0.5.px, // 边框宽度
                  ),
                )),
            child: Padding(
              padding: EdgeInsets.only(left: 10.px),
              child: Wrap(
                spacing: 10.px,
                children: leads.appCustomerTagList!
                    .map((e) => Chip(
                          label: WText(
                            e["tagName"],
                            style: TextStyle(
                                fontSize: WDimens.tsMedium,
                                color: WColors.mainTextColor),
                          ),
                        ))
                    .toList(),
              ),
            ),
          ),
        LabelItem(
          label: "备注",
          value: leads.remark,
          labelType: LabelType.TEXTAREA,
          isEnabled: false,
        ),
        CommonAttachment(
          key: picKey,
          picList: picList,
          picUrlList: picUrlList,
          enabled: false,
        )
      ],
    );
  }
}
